package com.heima.wemedia.controller.v1;

import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.media.dtos.WmMaterialDto;
import com.heima.wemedia.entity.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 素材分页查询
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public PageResult list(@RequestBody WmMaterialDto dto){
        return wmMaterialService.pageList(dto);

    }

    @PostMapping("/upload_picture")
    public ResponseResult<String> upload(@Param("multipartFile")MultipartFile multipartFile){
        return wmMaterialService.upload(multipartFile);

    }

    @DeleteMapping("/del_picture/{id}")
    public ResponseResult delete(@PathVariable Long id){
        return wmMaterialService.deleteById(id);

    }
    @PutMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable Long id){
        return wmMaterialService.collect(id);

    }
    @PutMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable Long id){
        return wmMaterialService.cancelCollect(id);

    }

}
